package controllers

import (
	"github.com/goravel/framework/contracts/http"
	"github.com/goravel/framework/facades"
	"goravel/app/models"
	"goravel/app/services"
)

type LoginLogController struct {
	DbServer services.DBServer
}

func NewLoginLogController() *LoginLogController {
	return &LoginLogController{
		DbServer: services.NewDBService(),
	}
}

// Index 登录日志列表
// @Summary      登录日志列表
// @Tags         System
// @Router       /system/login_log [get]
func (c *LoginLogController) Index(ctx http.Context) http.Response {
	var modelList []models.LoginLog
	query := facades.Orm().Query()
	//其他查询条件
	query = query.OrderBy("id", "desc")
	data, meta, err := c.DbServer.ListPage(ctx, &modelList, query, nil)
	if err != nil {
		return services.NewApiService(ctx).Error500(err.Error())
	}
	return services.NewApiService(ctx).DataPage(data, meta)
}
